From 4fec5625c4183f255fc77afc7a19f78426da7e08 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 26 Jun 2025 17:57:58 -0400 Subject: [PATCH] status: Add `soft-reboot-target` to JSON It's there in the human readable status. And update the soft-reboot test suite to assert things via JSON since it's *way* cleaner. --- src/ostree/ot-admin-builtin-status.c | 2 ++ tests/kolainst/data-shared/libinsttest.sh | 21 +++++++++++++++++++++ tests/kolainst/destructive/soft-reboot.sh | 14 ++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/ostree/ot-admin-builtin-status.c b/src/ostree/ot-admin-builtin-status.c index 2053b7ee..b84fbba2 100644 --- a/src/ostree/ot-admin-builtin-status.c +++ b/src/ostree/ot-admin-builtin-status.c @@ -208,6 +208,8 @@ deployment_write_json (OstreeSysroot *sysroot, OstreeRepo *repo, OstreeDeploymen ul_jsonwrt_value_boolean (jo, "rollback", is_rollback); ul_jsonwrt_value_boolean (jo, "finalization-locked", ostree_deployment_is_finalization_locked (deployment)); + ul_jsonwrt_value_boolean (jo, "soft-reboot-target", + ostree_deployment_is_soft_reboot_target (deployment)); ul_jsonwrt_value_boolean (jo, "staged", ostree_deployment_is_staged (deployment)); ul_jsonwrt_value_boolean (jo, "pinned", ostree_deployment_is_pinned (deployment)); OstreeDeploymentUnlockedState unlocked = ostree_deployment_get_unlocked (deployment); diff --git a/tests/kolainst/data-shared/libinsttest.sh b/tests/kolainst/data-shared/libinsttest.sh index abfcdb8e..0e35f2ce 100644 --- a/tests/kolainst/data-shared/libinsttest.sh +++ b/tests/kolainst/data-shared/libinsttest.sh @@ -79,3 +79,24 @@ rpmostree_query_json() { } host_commit=$(rpmostree_query_json '.deployments[0].checksum') host_osname=$(rpmostree_query_json '.deployments[0].osname') + +# $1 - json file +# $2+ - assertions +assert_jq() { + f=$1; shift + for expression in "$@"; do + if ! jq -e "${expression}" >/dev/null < $f; then + jq . < $f | sed -e 's/^/# /' >&2 + echo 1>&2 "${expression} failed to match $f" + exit 1 + fi + done +} + +# Assert that ostree admin status --json matches the provided jq predicates. +assert_status_jq() { + local t=$(mktemp --suffix=.json) + ostree admin status --json > $t + assert_jq $t "$@" + rm $t +} diff --git a/tests/kolainst/destructive/soft-reboot.sh b/tests/kolainst/destructive/soft-reboot.sh index 25624c03..84365258 100755 --- a/tests/kolainst/destructive/soft-reboot.sh +++ b/tests/kolainst/destructive/soft-reboot.sh @@ -12,6 +12,7 @@ case "${AUTOPKGTEST_REBOOT_MARK:-}" in systemctl mask --now zincati assert_streq $(systemctl show -P SoftRebootsCount) 0 + assert_status_jq '.deployments[0].pending | not' '.deployments[0].["soft-reboot-target"] | not' # Create a synthetic commit for upgrade cd /ostree/repo/tmp @@ -21,14 +22,21 @@ case "${AUTOPKGTEST_REBOOT_MARK:-}" in newcommit=$(ostree rev-parse soft-reboot-test) # Deploy the new commit normally first ostree admin deploy --stage soft-reboot-test - + + assert_status_jq '.deployments[0].pending' '.deployments[0].["soft-reboot-target"] | not' + # Test prepare-soft-reboot command echo "Testing prepare-soft-reboot..." ostree admin prepare-soft-reboot 0 - + + # Test human readable format ostree admin status > status.txt assert_file_has_content_literal status.txt '(pending) (soft-reboot)' + # And via JSON + assert_status_jq '.deployments[0].pending' '.deployments[0].["soft-reboot-target"]' + + # Verify the internal state file test -f /run/ostree/nextroot-booted /tmp/autopkgtest-soft-reboot "2" @@ -45,6 +53,8 @@ case "${AUTOPKGTEST_REBOOT_MARK:-}" in exit 1 fi + assert_status_jq '.deployments[0].booted' '.deployments[0].["soft-reboot-target"] | not' + test -f /etc/new-file-for-soft-reboot test -f /usr/share/test-file-for-soft-reboot -- 2.30.2